package com.ttl.bc.stock.request2.db;

import java.io.UnsupportedEncodingException;

import java.util.ArrayList;

import java.util.Date;
import java.util.HashSet;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;


import com.ttl.bc.ic.stkissue.bean.BCStkIssueSubBean;
import com.ttl.bc.ic.stkissue.db.BCStkIssueDAO;
import com.ttl.bc.master.department.BCDepartmentDAO;
import com.ttl.bc.master.issuetype.BCIssueTypeBean;
import com.ttl.bc.master.project.BCProjectBean;
import com.ttl.bc.stock.request2.action.BCStkIssue2Form;
import com.ttl.bc.stock.request2.bean.BCStkIssue2;
import com.ttl.bc.stock.request2.bean.BCStkIssue2ShowBean;
import com.ttl.bc.stock.request2.bean.BCStkIssueSub2;
import com.ttl.common.user.department.ITTL_UserDepartment;
import com.ttl.common.util.CommonUtils;
import com.ttl.common.util.Page;

public class BCStkIssue2BO {

	public static BCStkIssue2Form setForm(HttpServletRequest request) {
		
		BCStkIssue2Form stkIssue2Form = new BCStkIssue2Form();
		
		stkIssue2Form.setDocNo(request.getParameter("docNo"));
		
		//System.out.println("\n\n\\n\n\n\n\n\n\nn: "+request.getParameter("docNo"));
		stkIssue2Form.setDocDate(request.getParameter("docDate"));				
		
		stkIssue2Form.setProjectCode(request.getParameter("projectCode"));
		stkIssue2Form.setPersonCode(request.getParameter("personCode"));
		
		stkIssue2Form.setiTTL_deptPay(request.getParameter("iTTL_deptPay"));
		try {			
			stkIssue2Form.setMyDescription(new String(request.getParameter("myDescription").getBytes("ISO8859_1"),"UTF-8"));						
		}catch (Exception e) {}
			
		try {			
			stkIssue2Form.setItemName1(new String(request.getParameter("itemName1").getBytes("ISO8859_1"),"UTF-8"));
			stkIssue2Form.setUnitName1(new String(request.getParameter("unitName1").getBytes("ISO8859_1"),"UTF-8"));
			stkIssue2Form.setDivision1(new String(request.getParameter("division1").getBytes("ISO8859_1"),"UTF-8"));
		}catch (Exception e) {}
		
		try {
			stkIssue2Form.setItemName2(new String(request.getParameter("itemName2").getBytes("ISO8859_1"),"UTF-8"));
			stkIssue2Form.setUnitName2(new String(request.getParameter("unitName2").getBytes("ISO8859_1"),"UTF-8"));
			stkIssue2Form.setDivision2(new String(request.getParameter("division2").getBytes("ISO8859_1"),"UTF-8"));
		}catch (Exception e) {}
		
		try {
			stkIssue2Form.setItemName3(new String(request.getParameter("itemName3").getBytes("ISO8859_1"),"UTF-8"));
			stkIssue2Form.setUnitName3(new String(request.getParameter("unitName3").getBytes("ISO8859_1"),"UTF-8"));
			stkIssue2Form.setDivision3(new String(request.getParameter("division3").getBytes("ISO8859_1"),"UTF-8"));
		}catch (Exception e) {}
		
		try {
			stkIssue2Form.setItemName4(new String(request.getParameter("itemName4").getBytes("ISO8859_1"),"UTF-8"));
			stkIssue2Form.setUnitName4(new String(request.getParameter("unitName4").getBytes("ISO8859_1"),"UTF-8"));
			stkIssue2Form.setDivision4(new String(request.getParameter("division4").getBytes("ISO8859_1"),"UTF-8"));
		}catch (Exception e) {}
		
				
		//issue2.setMyDescription(new String(stkIssue2Form.getMyDescription().getBytes("ISO8859_1"),"utf-8"));
		
		stkIssue2Form.setDepartCode(request.getParameter("departCode"))	;						
		stkIssue2Form.setIssueType(request.getParameter("issueType"));
		
		stkIssue2Form.setItemCode1(request.getParameter("itemCode1"));
		stkIssue2Form.setShortName1(request.getParameter("shortName1"));
//		stkIssue2Form.setWhCode1(request.getParameter("whCode1"));
//		stkIssue2Form.setShelfCode1(request.getParameter("shelfCode1"));
		stkIssue2Form.setUnitCode1(request.getParameter("unitCode1"));
		stkIssue2Form.setQty1(request.getParameter("qty1"));		
		stkIssue2Form.setPrice1(request.getParameter("price1"));		
		stkIssue2Form.setAmount1(request.getParameter("amount1"));						
		
		stkIssue2Form.setItemCode2(request.getParameter("itemCode2"));	
		stkIssue2Form.setShortName2(request.getParameter("shortName2"));
//		stkIssue2Form.setWhCode2(request.getParameter("whCode2"));
//		stkIssue2Form.setShelfCode2(request.getParameter("shelfCode2"));
		stkIssue2Form.setUnitCode2(request.getParameter("unitCode2"));
		stkIssue2Form.setQty2(request.getParameter("qty2"));		
		stkIssue2Form.setPrice2(request.getParameter("price2"));
		stkIssue2Form.setAmount2(request.getParameter("amount2"));
		
		stkIssue2Form.setItemCode3(request.getParameter("itemCode3"));
		stkIssue2Form.setShortName3(request.getParameter("shortName3"));
//		stkIssue2Form.setWhCode3(request.getParameter("whCode3"));
//		stkIssue2Form.setShelfCode3(request.getParameter("shelfCode3"));
		stkIssue2Form.setUnitCode3(request.getParameter("unitCode3"));
		stkIssue2Form.setQty3(request.getParameter("qty3"));		
		stkIssue2Form.setPrice3(request.getParameter("price3"));
		stkIssue2Form.setAmount3(request.getParameter("amount3"));
		
		stkIssue2Form.setItemCode4(request.getParameter("itemCode4"));
		stkIssue2Form.setShortName4(request.getParameter("shortName4"));
//		stkIssue2Form.setWhCode4(request.getParameter("whCode4"));
//		stkIssue2Form.setShelfCode4(request.getParameter("shelfCode4"));
		stkIssue2Form.setUnitCode4(request.getParameter("unitCode4"));
		stkIssue2Form.setQty4(request.getParameter("qty4"));													
		stkIssue2Form.setPrice4(request.getParameter("price4"));
		stkIssue2Form.setAmount4(request.getParameter("amount4"));
		
		return stkIssue2Form;
	}
	
	@SuppressWarnings("unchecked")
	public boolean add(ActionForm form, HttpServletRequest request,
			HttpServletResponse response) {
			
			BCStkIssue2Form stkIssue2Form = setForm(request);//(BCStkIssue2Form)form;
			
			BCIssueTypeBean issueType = new BCIssueTypeBean();
			issueType.setCode(request.getParameter("issueType"));			
			
			BCProjectBean proj = new BCProjectBean();
			proj.setCode(stkIssue2Form.getProjectCode());
			
			BCStkIssue2 issue2 = new BCStkIssue2();
			issue2.setBcIssueTypeBean(issueType);
			//issue2.setBcProjectBean(proj);
			issue2.setProjectCode(stkIssue2Form.getProjectCode());
			issue2.setiTTL_status("0");
			issue2.setBillStatus(0);
			issue2.setIsCancel(0);
			issue2.setIttl_userLevel((Integer)request.getSession().getAttribute("userLevel"));			
			issue2.setDocNo(stkIssue2Form.getDocNo());
			issue2.setCreatorCode(stkIssue2Form.getPersonCode());
			issue2.setDepartCode(stkIssue2Form.getDepartCode());
						
//			try {    							    
//				String str_date = stkIssue2Form.getDocDate();
//			
//	        	DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); 
//	        	Date date = (Date)formatter.parse(str_date);    		        		        		        
//		        issue2.setDocDate(date);
//		        issue2.setCreateDateTime(new Date());		        
//		   } catch (ParseException e) {
//			   System.out.println("Exception :"+e);    
//		   }
	        issue2.setDocDate(CommonUtils.convertStringToDate(stkIssue2Form.getDocDate()));
	        issue2.setCreateDateTime(new Date());
		   			
			issue2.setIsCompleteSave(1);
			issue2.setIssueType(stkIssue2Form.getIssueType());
			issue2.setiTTL_orderNo(stkIssue2Form.getOrderNo());
			issue2.setiTTL_deptPay(stkIssue2Form.getiTTL_deptPay());
			issue2.setPersonCode(stkIssue2Form.getPersonCode());
			//issue2.setProjectCode(stkIssue2Form.getProjectCode());
			issue2.setMyDescription(stkIssue2Form.getMyDescription());
//			issue2.setMyDescription(new String(stkIssue2Form.getMyDescription().getBytes("ISO8859_1"),"utf-8"));
			
			HashSet s = new HashSet();			
			
	//		issueSub2.setBcStkIssue2(issue2);
			
			if( stkIssue2Form.getItemCode1() != null) {
				BCStkIssueSub2 issueSub2 = new BCStkIssueSub2();
				
				issueSub2.setDepartCode(stkIssue2Form.getDepartCode());
				issueSub2.setDocDate(new Date());
				issueSub2.setIssueType(stkIssue2Form.getIssueType());				
				issueSub2.setItemCode(stkIssue2Form.getItemCode1());
				issueSub2.setItemName(stkIssue2Form.getItemName1());
				issueSub2.setIttl_itemCode_ttl2(stkIssue2Form.getShortName1());
				issueSub2.setQty(Float.valueOf(stkIssue2Form.getQty1()));
				issueSub2.setRemainQty(Float.valueOf(stkIssue2Form.getQty1()));
				
				issueSub2.setUnitCode(stkIssue2Form.getUnitCode1());
//				BCItemUnitBean itemU = new BCItemUnitBean();
//				itemU.setCode(stkIssue2Form.getUnitCode1());
//				issueSub2.setBcitemUnit(itemU);				
//				issueSub2.setWhCode(stkIssue2Form.getWhCode1());
				issueSub2.setWhCode("10");
				
				issueSub2.setLineNumber(1);
				issueSub2.setIttl_unitName(stkIssue2Form.getUnitName1());
				issueSub2.setIttl_division(stkIssue2Form.getDivision1());								
				
				//issueSub2.setShelfCode( request.getParameter("shelfCode1") );
//				BCShelfBean shelf = new BCShelfBean();
////				shelf.setCode(request.getParameter("shelfCode1"));
//				shelf.setCode("10");
//				issueSub2.setBcShelf(shelf);
				issueSub2.setShelfCode("10");
				issueSub2.setBcStkIssue2(issue2);
				
				issueSub2.setPersonCode(stkIssue2Form.getPersonCode());
				issueSub2.setProjectCode(stkIssue2Form.getProjectCode());
				issueSub2.setCreatorCode(stkIssue2Form.getPersonCode());
				issueSub2.setCreateDateTime(issue2.getCreateDateTime());
				
				s.add(issueSub2);
			}
			
			if(stkIssue2Form.getItemCode2() != null) {
				BCStkIssueSub2 issueSub2 = new BCStkIssueSub2();
				
				issueSub2.setDepartCode(stkIssue2Form.getDepartCode());
				issueSub2.setDocDate(new Date());
				issueSub2.setIssueType(stkIssue2Form.getIssueType());				
				issueSub2.setItemCode(stkIssue2Form.getItemCode2());
				issueSub2.setItemName(stkIssue2Form.getItemName2());
				issueSub2.setIttl_itemCode_ttl2(stkIssue2Form.getShortName2());
				issueSub2.setQty(Float.valueOf(stkIssue2Form.getQty2()));
				issueSub2.setRemainQty(Float.valueOf(stkIssue2Form.getQty2()));
				
				issueSub2.setUnitCode(stkIssue2Form.getUnitCode2());
//				BCItemUnitBean itemU = new BCItemUnitBean();
//				itemU.setCode(stkIssue2Form.getUnitCode2());
//				issueSub2.setBcitemUnit(itemU);
				
//				issueSub2.setWhCode(stkIssue2Form.getWhCode2());
				issueSub2.setWhCode("10");
				
				issueSub2.setLineNumber(2);
				issueSub2.setIttl_unitName(stkIssue2Form.getUnitName2());
				issueSub2.setIttl_division(stkIssue2Form.getDivision2());
				
				//issueSub2.setShelfCode(stkIssue2Form.getShelfCode2());				
				//issueSub2.setShelfCode( request.getParameter("shelfCode2") );
//				BCShelfBean shelf = new BCShelfBean();
////				shelf.setCode(request.getParameter("shelfCode2"));
//				shelf.setCode("10");				
//				issueSub2.setBcShelf(shelf);
				issueSub2.setShelfCode("10");
				
				issueSub2.setBcStkIssue2(issue2);

				issueSub2.setPersonCode(stkIssue2Form.getPersonCode());
				issueSub2.setProjectCode(stkIssue2Form.getProjectCode());
				issueSub2.setCreatorCode(stkIssue2Form.getPersonCode());
				issueSub2.setCreateDateTime(issue2.getCreateDateTime());
				
				s.add(issueSub2);
			}		
			
			if( stkIssue2Form.getItemCode3() != null) {
				BCStkIssueSub2 issueSub2 = new BCStkIssueSub2();				
				issueSub2.setDepartCode(stkIssue2Form.getDepartCode());
				issueSub2.setDocDate(new Date());
				issueSub2.setIssueType(stkIssue2Form.getIssueType());
				
				issueSub2.setItemCode(stkIssue2Form.getItemCode3());
				issueSub2.setItemName(stkIssue2Form.getItemName3());
				issueSub2.setIttl_itemCode_ttl2(stkIssue2Form.getShortName3());
				issueSub2.setQty(Float.valueOf(stkIssue2Form.getQty3()));
				issueSub2.setRemainQty(Float.valueOf(stkIssue2Form.getQty3()));
				
				issueSub2.setUnitCode(stkIssue2Form.getUnitCode3());
//				BCItemUnitBean itemU = new BCItemUnitBean();
//				itemU.setCode(stkIssue2Form.getUnitCode3());
//				issueSub2.setBcitemUnit(itemU);
				
//				issueSub2.setWhCode(stkIssue2Form.getWhCode3());
				issueSub2.setWhCode("10");				
				issueSub2.setLineNumber(3);
				issueSub2.setIttl_unitName(stkIssue2Form.getUnitName3());
				issueSub2.setIttl_division(stkIssue2Form.getDivision3());
				
				//issueSub2.setShelfCode(stkIssue2Form.getShelfCode3());				
				//issueSub2.setShelfCode( request.getParameter("shelfCode3") );
//				BCShelfBean shelf = new BCShelfBean();
////				shelf.setCode(request.getParameter("shelfCode3"));
//				shelf.setCode("10");
//				
//				issueSub2.setBcShelf(shelf);
				issueSub2.setShelfCode("10");
				issueSub2.setBcStkIssue2(issue2);
				
				issueSub2.setPersonCode(stkIssue2Form.getPersonCode());
				issueSub2.setProjectCode(stkIssue2Form.getProjectCode());
				issueSub2.setCreatorCode(stkIssue2Form.getPersonCode());
				issueSub2.setCreateDateTime(issue2.getCreateDateTime());
				
				s.add(issueSub2);
			}		
			
			if(stkIssue2Form.getItemCode4() != null) {
				BCStkIssueSub2 issueSub2 = new BCStkIssueSub2();				
				issueSub2.setDepartCode(stkIssue2Form.getDepartCode());
				issueSub2.setDocDate(new Date());
				issueSub2.setIssueType(stkIssue2Form.getIssueType());				
				issueSub2.setItemCode(stkIssue2Form.getItemCode4());
				issueSub2.setItemName(stkIssue2Form.getItemName4());
				issueSub2.setIttl_itemCode_ttl2(stkIssue2Form.getShortName4());
				issueSub2.setQty(Float.valueOf(stkIssue2Form.getQty4()));
				issueSub2.setRemainQty(Float.valueOf(stkIssue2Form.getQty4()));
				
				issueSub2.setUnitCode(stkIssue2Form.getUnitCode4());
//				BCItemUnitBean itemU = new BCItemUnitBean();
//				itemU.setCode(stkIssue2Form.getUnitCode4());
//				issueSub2.setBcitemUnit(itemU);				
//				issueSub2.setWhCode(stkIssue2Form.getWhCode4());
				issueSub2.setWhCode("10");				
				issueSub2.setLineNumber(4);
				issueSub2.setIttl_unitName(stkIssue2Form.getUnitName4());
				issueSub2.setIttl_division(stkIssue2Form.getDivision4());
				
				//issueSub2.setShelfCode(stkIssue2Form.getShelfCode4());				
				//issueSub2.setShelfCode( request.getParameter("shelfCode4") );
//				BCShelfBean shelf = new BCShelfBean();
////				shelf.setCode(request.getParameter("shelfCode4"));
//				shelf.setCode("10");
//				issueSub2.setBcShelf(shelf);
				issueSub2.setShelfCode("10");
				issueSub2.setBcStkIssue2(issue2);
				
				issueSub2.setPersonCode(stkIssue2Form.getPersonCode());
				issueSub2.setProjectCode(stkIssue2Form.getProjectCode());
				issueSub2.setCreatorCode(stkIssue2Form.getPersonCode());
				issueSub2.setCreateDateTime(issue2.getCreateDateTime());
				
				s.add(issueSub2);
			}
						
			issue2.setBcStkIssueSub2s(s);
									
			BCStkIssue2DAO dao = new BCStkIssue2DAO();
			String hql = "FROM BCStkIssue2 WHERE docNo = '"+issue2.getDocNo()+"' ";
			List al = dao.find(hql);
			if(al.size()==0) {
				request.setAttribute("docNoPrint", issue2.getDocNo());
				return dao.add(issue2);
			}else {
				String maxDocNo = CommonUtils.getMaxDocNo(issue2.getDocNo().substring(0, 5));
				issue2.setDocNo(maxDocNo);
				request.setAttribute("docNoPrint", issue2.getDocNo());
				return dao.add(issue2);
			}
			
	}

	@SuppressWarnings("unchecked")
	public List findPrint(String hql) throws Exception {
		BCStkIssue2DAO dao = new BCStkIssue2DAO();
		List results = dao.find(hql);
		return results;		
	}

	@SuppressWarnings("unchecked")
	public List delete(HttpServletRequest request) throws Exception {
		
		String docNo = (String)request.getParameter("docNo");
		String hql = "from BCStkIssue2 where docNo = '"+docNo+"'";
		hql = hql + " and billStatus=0 and isCancel =0 ";
		
		System.out.println("#docNo :"+docNo);
		
		BCStkIssue2DAO dao = new BCStkIssue2DAO();
		dao.delete(hql);
		
		List result = find(request); 
		return result;		
	}
	
	@SuppressWarnings("unchecked")
	public List find(HttpServletRequest request) throws Exception {
		
		String userName = (String)request.getSession().getAttribute("userName");
		
		String docNoFind = (String)request.getParameter("docNoFind");
		String monthFind = (String)request.getParameter("monthFind");
		String yearFind = (String)request.getParameter("yearFind");
		String preDocNo  = (String)request.getSession().getAttribute("preDocNo");
		int userLevel =  (Integer)request.getSession().getAttribute("userLevel");
		
		if(monthFind==null) {			
			monthFind = CommonUtils.getCurrentDateFormat("MM");										
		}
		
		if(yearFind==null) {
			yearFind = CommonUtils.getCurrentDateFormat("yyyyy");
			
			if (Integer.parseInt(yearFind)<2500) {								
				yearFind = (""+(Integer.parseInt(yearFind)+543)).substring(2);			
			}else {
				yearFind = yearFind.substring(2);
			}			
		}
				
		request.getSession().setAttribute("monthFind", monthFind);
		request.getSession().setAttribute("yearFind", yearFind);
				
		String hql = "";
		
		if(docNoFind==null||docNoFind.trim().equals("")) {
			hql = "FROM BCStkIssue2 s  " +
					 "WHERE upper(s.creatorCode)='"+userName.toUpperCase()+"' " +
					 "and s.docNo like '"+preDocNo+"-"+yearFind+monthFind+"%' "+
					 "and s.isCancel =0 "+
					 "ORDER BY s.docNo desc";
		}else {
			hql = "FROM BCStkIssue2 s  " +
			 "WHERE upper(s.creatorCode)='"+userName.toUpperCase()+"' " +
			 "and s.docNo like '"+preDocNo+"-%"+docNoFind.trim()+"%' "+
			 "and s.isCancel =0 "+
			 "ORDER BY s.docNo desc";
			request.getSession().setAttribute("docNoFind", docNoFind.trim());
		}
						
//		String userName = (String)request.getSession().getAttribute("userName");
//		String hql = "FROM BCStkIssue2  WHERE creatorCode='"+userName+"' ORDER BY docNo desc";		
//		System.out.print(hql);
		
		BCStkIssue2DAO dao = new BCStkIssue2DAO();
		List results = dao.find(hql);
		
		//สร้าง ArrayList หลักไว้สำหรับ รวมกันของผล 2 hql
		ArrayList<BCStkIssue2ShowBean> alUnion = new ArrayList<BCStkIssue2ShowBean>();
		String docNoNotIn = "";
		if(results!=null) {			
			ArrayList<BCStkIssue2ShowBean> al = getBCStkIssue2ShowBean(results);			
			for(int i=0; i<al.size(); i++) {
				alUnion.add(al.get(i));
				docNoNotIn = docNoNotIn + "'"+((BCStkIssue2ShowBean)al.get(i)).getDocNo()+"',"; 
			}
		}
		
		//สำหรับ userLevel
		if(docNoFind==null||docNoFind.trim().equals("")) {
			hql = "FROM BCStkIssue2 s  " +
			 "WHERE s.docNo like '"+preDocNo+"-"+yearFind+monthFind+"%' "+
			 "and s.isCancel =0 "+
			 " and s.ittl_userLevel <= "+userLevel;
			 	if(docNoNotIn.length()>0){
					docNoNotIn  =docNoNotIn.substring(0, docNoNotIn.length()-1);
					hql = hql+" and s.docNo not in ("+docNoNotIn+") ";
				}
			 hql = hql+" ORDER BY s.docNo desc";			
		}else {
			hql = "FROM BCStkIssue2 s  " +
			 " WHERE  s.docNo like '"+preDocNo+"-%"+docNoFind.trim()+"%' "+
			 " and s.isCancel =0 "+
			 " and s.ittl_userLevel <="+userLevel;
			 	if(docNoNotIn.length()>0){
					docNoNotIn  =docNoNotIn.substring(0, docNoNotIn.length()-1);
					hql = hql+" and s.docNo not in ("+docNoNotIn+") ";
				}
			 hql = hql+" ORDER BY s.docNo desc";				
		}
		
		List results2 = dao.find(hql);
		if(results2!=null) {					
			ArrayList<BCStkIssue2ShowBean> al = getBCStkIssue2ShowBean(results2);			
			for(int i=0; i<al.size(); i++) {
				alUnion.add(al.get(i));
			}
		}										
		results = alUnion;
		return results;
	}

	@SuppressWarnings("unchecked")
	private ArrayList<BCStkIssue2ShowBean> getBCStkIssue2ShowBean(List results) {
		ArrayList<BCStkIssue2ShowBean> al = new ArrayList<BCStkIssue2ShowBean>();
		
		for(int i=0; i<results.size(); i++) {
			BCStkIssue2 s2 = (BCStkIssue2)results.get(i);
			
			for(Object o: s2.getBcStkIssueSub2s()) {
				BCStkIssueSub2 sub2 = (BCStkIssueSub2)o; 			
				
				BCStkIssue2ShowBean bean = new BCStkIssue2ShowBean();
				bean.setDocNo(s2.getDocNo());
				bean.setDocDate(s2.getDocDate());
				bean.setMyDescription(s2.getMyDescription());
				bean.setBillStatus(s2.getBillStatus());					
				bean.setItemCode(sub2.getItemCode());
				bean.setItemName(sub2.getItemName());					
				bean.setQty(sub2.getQty());					
				bean.setIttl_unitName(sub2.getIttl_unitName());
				bean.setPrice(sub2.getPrice());
				bean.setAmount(sub2.getAmount());
				bean.setIttl_status(s2.getiTTL_status());
				bean.setMode("");
				
				al.add(bean);
			}				
		}
		return al;
	}

	@SuppressWarnings("unchecked")
	public Object findForm(HttpServletRequest request) {
		
		BCStkIssue2Form form = new BCStkIssue2Form();
		
		String docNo = (String)request.getParameter("docNo");
		System.out.println("#docNo :"+docNo);
		
		BCStkIssue2DAO dao = new BCStkIssue2DAO();	
		String hql = "FROM BCStkIssue2 h " +
				" WHERE upper(h.docNo) = '"+docNo.toUpperCase()+"' ";
				
		List results = dao.find(hql);
		if (results.size()>0) {
			
			for(int i=0; i<results.size(); i++) {				
				BCStkIssue2 s2 = (BCStkIssue2)results.get(i);
				
				form.setDepartCode(s2.getDepartCode());
				form.setDocNo(docNo);
				form.setDocDate(""+s2.getDocDate());
				
				System.out.println(form.getDocDate());
				
				form.setIssueType(s2.getBcIssueTypeBean().getCode());
				form.setIssueName(s2.getBcIssueTypeBean().getName());
				form.setMyDescription(s2.getMyDescription());
				form.setOrderNo(s2.getiTTL_orderNo());
				form.setPersonCode(s2.getPersonCode());
				form.setProjectCode(s2.getProjectCode());								
				
				//form.setProjectCode(s2.getBcProjectBean().getCode());
				//form.setProjectName(s2.getBcProjectBean().getName());
				form.setiTTL_deptPay(s2.getiTTL_deptPay());
				
				int id = 0;
				int countId = 0;
				for(Object o: s2.getBcStkIssueSub2s()) {
					countId++;
					BCStkIssueSub2 sub2 = (BCStkIssueSub2)o;
					id = sub2.getLineNumber();					
					switch (id) {
					case 1:						
						form.setItemCode1(sub2.getItemCode());
						form.setItemName1(sub2.getItemName());
						form.setShortName1(sub2.getIttl_itemCode_ttl2());
						form.setWhCode1(sub2.getWhCode());
						form.setShelfCode1(sub2.getShelfCode());
						//form.setShelfName1(sub2.getBcShelf().getName());						
						form.setUnitCode1(sub2.getUnitCode());
						form.setUnitName1(sub2.getIttl_unitName());
						form.setQty1(""+sub2.getQty());						
						form.setDivision1(sub2.getIttl_division());						
						form.setIttl_unitName1(sub2.getIttl_unitName());
						form.setPrice1(""+sub2.getPrice());
						form.setAmount1(""+sub2.getAmount());
						
						break;
					case 2:
						form.setItemCode2(sub2.getItemCode());
						form.setItemName2(sub2.getItemName());
						form.setShortName2(sub2.getIttl_itemCode_ttl2());
						form.setWhCode2(sub2.getWhCode());
						form.setShelfCode2(sub2.getShelfCode());
						//form.setShelfName2(sub2.getBcShelf().getName());						
						form.setUnitCode2(sub2.getUnitCode());
						form.setUnitName2(sub2.getIttl_unitName());
						form.setQty2(""+sub2.getQty());						
						form.setDivision2(sub2.getIttl_division());
						form.setIttl_unitName2(sub2.getIttl_unitName());
						form.setPrice2(""+sub2.getPrice());
						form.setAmount2(""+sub2.getAmount());
						
						break;
					case 3:
						form.setItemCode3(sub2.getItemCode());
						form.setItemName3(sub2.getItemName());
						form.setShortName3(sub2.getIttl_itemCode_ttl2());
						form.setWhCode3(sub2.getWhCode());
						form.setShelfCode3(sub2.getShelfCode());
						//form.setShelfName3(sub2.getBcShelf().getName());
						form.setUnitCode3(sub2.getUnitCode());
						form.setUnitName3(sub2.getIttl_unitName());
						form.setQty3(""+sub2.getQty());						
						form.setDivision3(sub2.getIttl_division());
						form.setIttl_unitName3(sub2.getIttl_unitName());
						form.setPrice3(""+sub2.getPrice());
						form.setAmount3(""+sub2.getAmount());						
						break;		
					case 4:
						form.setItemCode4(sub2.getItemCode());
						form.setItemName4(sub2.getItemName());
						form.setShortName4(sub2.getIttl_itemCode_ttl2());
						form.setWhCode4(sub2.getWhCode());
						form.setShelfCode4(sub2.getShelfCode());
						//form.setShelfName4(sub2.getBcShelf().getName());
						form.setUnitCode4(sub2.getUnitCode());
						form.setUnitName4(sub2.getIttl_unitName());
						form.setQty4(""+sub2.getQty());						
						form.setDivision4(sub2.getIttl_division());
						form.setIttl_unitName4(sub2.getIttl_unitName());
						form.setPrice4(""+sub2.getPrice());
						form.setAmount4(""+sub2.getAmount());						
						break;						
					}	
				}
				request.setAttribute("countId", countId);
			}			
		}	
		return form;
	}
	
	@SuppressWarnings("unchecked")
	public boolean updateForApprove(ActionForm form, HttpServletRequest request,
			HttpServletResponse response) {

		BCStkIssue2Form stkIssue2Form = setForm(request);//(BCStkIssue2Form)form;
		
		BCIssueTypeBean issueType = new BCIssueTypeBean();
		issueType.setCode(request.getParameter("issueType"));			
		BCProjectBean proj = new BCProjectBean();
		proj.setCode(stkIssue2Form.getProjectCode());
		
		BCStkIssue2 issue2 = new BCStkIssue2();
		issue2.setBcIssueTypeBean(issueType);
		issue2.setProjectCode(stkIssue2Form.getProjectCode());
		issue2.setiTTL_status("3");
		issue2.setBillStatus(0);
		issue2.setIsCancel(0);
		issue2.setIttl_userLevel((Integer)request.getSession().getAttribute("userLevel"));
		issue2.setDocNo(stkIssue2Form.getDocNo());
		issue2.setCreatorCode(stkIssue2Form.getPersonCode());
		issue2.setDepartCode(stkIssue2Form.getDepartCode());					        	       
	    issue2.setDocDate(CommonUtils.convertStringToDate(stkIssue2Form.getDocDate()));
	       	    	  								
		issue2.setIsCompleteSave(1);
		issue2.setIssueType(stkIssue2Form.getIssueType());
		issue2.setiTTL_orderNo(stkIssue2Form.getOrderNo());
		issue2.setiTTL_deptPay(stkIssue2Form.getiTTL_deptPay());
		issue2.setPersonCode(stkIssue2Form.getPersonCode());
		issue2.setMyDescription(stkIssue2Form.getMyDescription());
		
		HashSet s = new HashSet();			
		
		if( stkIssue2Form.getItemCode1() != null) {
			BCStkIssueSub2 issueSub2 = new BCStkIssueSub2();
			
			issueSub2.setDepartCode(stkIssue2Form.getDepartCode());
			issueSub2.setDocDate(new Date());
			issueSub2.setIssueType(stkIssue2Form.getIssueType());
			
			issueSub2.setItemCode(stkIssue2Form.getItemCode1());
			issueSub2.setItemName(stkIssue2Form.getItemName1());
			issueSub2.setIttl_itemCode_ttl2(stkIssue2Form.getShortName1());
			issueSub2.setQty(Float.valueOf(stkIssue2Form.getQty1()));
			issueSub2.setRemainQty(Float.valueOf(stkIssue2Form.getQty1()));
										
			issueSub2.setPrice(Double.valueOf(stkIssue2Form.getPrice1()));
			issueSub2.setAmount(Double.valueOf(stkIssue2Form.getAmount1()));
			
//			BCItemUnitBean itemU = new BCItemUnitBean();
//			itemU.setCode(stkIssue2Form.getUnitCode1());
//			issueSub2.setBcitemUnit(itemU);
			issueSub2.setUnitCode(stkIssue2Form.getUnitCode1());
//			issueSub2.setWhCode(stkIssue2Form.getWhCode1());
			issueSub2.setWhCode("10");
			
			issueSub2.setLineNumber(1);
			issueSub2.setIttl_unitName(stkIssue2Form.getUnitName1());
			issueSub2.setIttl_division(stkIssue2Form.getDivision1());			
			
			//issueSub2.setShelfCode( request.getParameter("shelfCode1") );
//			BCShelfBean shelf = new BCShelfBean();
////			shelf.setCode(request.getParameter("shelfCode1"));
//			shelf.setCode("10");
//			issueSub2.setBcShelf(shelf);
			issueSub2.setShelfCode("10");
			issueSub2.setIttl_status("3");
			issueSub2.setBcStkIssue2(issue2);

			issueSub2.setPersonCode(stkIssue2Form.getPersonCode());
			issueSub2.setProjectCode(stkIssue2Form.getProjectCode());
			
			s.add(issueSub2);
		}
		
		if(stkIssue2Form.getItemCode2() != null) {
			BCStkIssueSub2 issueSub2 = new BCStkIssueSub2();
			
			issueSub2.setDepartCode(stkIssue2Form.getDepartCode());
			issueSub2.setDocDate(new Date());
			issueSub2.setIssueType(stkIssue2Form.getIssueType());
			
			issueSub2.setItemCode(stkIssue2Form.getItemCode2());
			issueSub2.setItemName(stkIssue2Form.getItemName2());
			issueSub2.setIttl_itemCode_ttl2(stkIssue2Form.getShortName2());
			issueSub2.setQty(Float.valueOf(stkIssue2Form.getQty2()));
			issueSub2.setRemainQty(Float.valueOf(stkIssue2Form.getQty2()));
			issueSub2.setPrice(Double.valueOf(stkIssue2Form.getPrice2()));
			issueSub2.setAmount(Double.valueOf(stkIssue2Form.getAmount2()));			
			issueSub2.setUnitCode(stkIssue2Form.getUnitCode2());
			
//			BCItemUnitBean itemU = new BCItemUnitBean();
//			itemU.setCode(stkIssue2Form.getUnitCode2());
//			issueSub2.setBcitemUnit(itemU);
			
//			issueSub2.setWhCode(stkIssue2Form.getWhCode2());
			issueSub2.setWhCode("10");
			issueSub2.setIttl_status("3");
			issueSub2.setLineNumber(2);
			issueSub2.setIttl_unitName(stkIssue2Form.getUnitName2());
			issueSub2.setIttl_division(stkIssue2Form.getDivision2());			
			//issueSub2.setShelfCode(stkIssue2Form.getShelfCode2());				
			//issueSub2.setShelfCode( request.getParameter("shelfCode2") );
//			BCShelfBean shelf = new BCShelfBean();
////			shelf.setCode(request.getParameter("shelfCode2"));
//			shelf.setCode("10");
//			issueSub2.setBcShelf(shelf);
			issueSub2.setShelfCode("10");
			issueSub2.setBcStkIssue2(issue2);

			issueSub2.setPersonCode(stkIssue2Form.getPersonCode());
			issueSub2.setProjectCode(stkIssue2Form.getProjectCode());
			
			s.add(issueSub2);
		}		
		
		if( stkIssue2Form.getItemCode3() != null) {
			BCStkIssueSub2 issueSub2 = new BCStkIssueSub2();
			
			issueSub2.setDepartCode(stkIssue2Form.getDepartCode());
			issueSub2.setDocDate(new Date());
			issueSub2.setIssueType(stkIssue2Form.getIssueType());
			
			issueSub2.setItemCode(stkIssue2Form.getItemCode3());
			issueSub2.setItemName(stkIssue2Form.getItemName3());
			issueSub2.setIttl_itemCode_ttl2(stkIssue2Form.getShortName3());
			issueSub2.setQty(Float.valueOf(stkIssue2Form.getQty3()));
			issueSub2.setRemainQty(Float.valueOf(stkIssue2Form.getQty3()));
			issueSub2.setPrice(Double.valueOf(stkIssue2Form.getPrice3()));
			issueSub2.setAmount(Double.valueOf(stkIssue2Form.getAmount3()));			
			issueSub2.setUnitCode(stkIssue2Form.getUnitCode3());
//			BCItemUnitBean itemU = new BCItemUnitBean();
//			itemU.setCode(stkIssue2Form.getUnitCode3());
//			issueSub2.setBcitemUnit(itemU);

			
//			issueSub2.setWhCode(stkIssue2Form.getWhCode3());
			issueSub2.setWhCode("10");
			issueSub2.setIttl_status("3");
			issueSub2.setLineNumber(3);
			issueSub2.setIttl_unitName(stkIssue2Form.getUnitName3());
			issueSub2.setIttl_division(stkIssue2Form.getDivision3());			
			//issueSub2.setShelfCode(stkIssue2Form.getShelfCode3());				
			//issueSub2.setShelfCode( request.getParameter("shelfCode3") );
//			BCShelfBean shelf = new BCShelfBean();
////			shelf.setCode(request.getParameter("shelfCode3"));
//			shelf.setCode("10");
//			issueSub2.setBcShelf(shelf);
			issueSub2.setShelfCode("10");
			
			issueSub2.setBcStkIssue2(issue2);
			issueSub2.setPersonCode(stkIssue2Form.getPersonCode());
			issueSub2.setProjectCode(stkIssue2Form.getProjectCode());
			
			s.add(issueSub2);
		}		
		
		if(stkIssue2Form.getItemCode4() != null) {
			BCStkIssueSub2 issueSub2 = new BCStkIssueSub2();
			
			issueSub2.setDepartCode(stkIssue2Form.getDepartCode());
			issueSub2.setDocDate(new Date());
			issueSub2.setIssueType(stkIssue2Form.getIssueType());
			
			issueSub2.setItemCode(stkIssue2Form.getItemCode4());
			issueSub2.setItemName(stkIssue2Form.getItemName4());
			issueSub2.setIttl_itemCode_ttl2(stkIssue2Form.getShortName4());
			issueSub2.setQty(Float.valueOf(stkIssue2Form.getQty4()));
			issueSub2.setRemainQty(Float.valueOf(stkIssue2Form.getQty4()));
			issueSub2.setPrice(Double.valueOf(stkIssue2Form.getPrice4()));
			issueSub2.setAmount(Double.valueOf(stkIssue2Form.getAmount4()));			
			issueSub2.setUnitCode(stkIssue2Form.getUnitCode4());
//			BCItemUnitBean itemU = new BCItemUnitBean();
//			itemU.setCode(stkIssue2Form.getUnitCode4());
//			issueSub2.setBcitemUnit(itemU);
			
//			issueSub2.setWhCode(stkIssue2Form.getWhCode4());
			issueSub2.setWhCode("10");
			issueSub2.setIttl_status("3");
			issueSub2.setLineNumber(4);
			issueSub2.setIttl_unitName(stkIssue2Form.getUnitName4());
			issueSub2.setIttl_division(stkIssue2Form.getDivision4());			
			//issueSub2.setShelfCode(stkIssue2Form.getShelfCode4());				
			//issueSub2.setShelfCode( request.getParameter("shelfCode4") );
//			BCShelfBean shelf = new BCShelfBean();
////			shelf.setCode(request.getParameter("shelfCode4"));
//			shelf.setCode("10");
//			issueSub2.setBcShelf(shelf);
			issueSub2.setShelfCode("10");
			
			
			issueSub2.setBcStkIssue2(issue2);
			issueSub2.setPersonCode(stkIssue2Form.getPersonCode());
			issueSub2.setProjectCode(stkIssue2Form.getProjectCode());
			
			s.add(issueSub2);
		}
				
		issue2.setBcStkIssueSub2s(s);
							
		BCStkIssue2DAO dao = new BCStkIssue2DAO();		
		dao.update(issue2.getDocNo(),issue2);
								
		return true;

	}
	@SuppressWarnings("unchecked")
	public boolean update(ActionForm form, HttpServletRequest request,
			HttpServletResponse response) {

		BCStkIssue2Form stkIssue2Form = setForm(request);//(BCStkIssue2Form)form;
		
		BCIssueTypeBean issueType = new BCIssueTypeBean();
		issueType.setCode(request.getParameter("issueType"));			
		BCProjectBean proj = new BCProjectBean();
		proj.setCode(stkIssue2Form.getProjectCode());
		
		BCStkIssue2 issue2 = new BCStkIssue2();
		issue2.setBcIssueTypeBean(issueType);
		issue2.setProjectCode(stkIssue2Form.getProjectCode());
		issue2.setiTTL_status("0");
		issue2.setBillStatus(0);
		issue2.setIsCancel(0);
		issue2.setIttl_userLevel((Integer)request.getSession().getAttribute("userLevel"));
		issue2.setDocNo(stkIssue2Form.getDocNo());
		issue2.setCreatorCode(stkIssue2Form.getPersonCode());
		issue2.setDepartCode(stkIssue2Form.getDepartCode());					        	       
	    issue2.setDocDate(CommonUtils.convertStringToDate(stkIssue2Form.getDocDate()));
	       	    	  								
		issue2.setIsCompleteSave(1);
		issue2.setIssueType(stkIssue2Form.getIssueType());
		issue2.setiTTL_orderNo(stkIssue2Form.getOrderNo());
		issue2.setiTTL_deptPay(stkIssue2Form.getiTTL_deptPay());
		issue2.setPersonCode(stkIssue2Form.getPersonCode());
		issue2.setMyDescription(stkIssue2Form.getMyDescription());
		
		HashSet s = new HashSet();			
		
		if( stkIssue2Form.getItemCode1() != null) {
			BCStkIssueSub2 issueSub2 = new BCStkIssueSub2();
			
			issueSub2.setDepartCode(stkIssue2Form.getDepartCode());
			issueSub2.setDocDate(new Date());
			issueSub2.setIssueType(stkIssue2Form.getIssueType());
			
			issueSub2.setItemCode(stkIssue2Form.getItemCode1());
			issueSub2.setItemName(stkIssue2Form.getItemName1());
			issueSub2.setIttl_itemCode_ttl2(stkIssue2Form.getShortName1());
			issueSub2.setQty(Float.valueOf(stkIssue2Form.getQty1()));
			issueSub2.setRemainQty(Float.valueOf(stkIssue2Form.getQty1()));
										
			issueSub2.setPrice(Double.valueOf(stkIssue2Form.getPrice1()));
			issueSub2.setAmount(Double.valueOf(stkIssue2Form.getAmount1()));
			
//			BCItemUnitBean itemU = new BCItemUnitBean();
//			itemU.setCode(stkIssue2Form.getUnitCode1());
//			issueSub2.setBcitemUnit(itemU);
			issueSub2.setUnitCode(stkIssue2Form.getUnitCode1());
//			issueSub2.setWhCode(stkIssue2Form.getWhCode1());
			issueSub2.setWhCode("10");
			
			issueSub2.setLineNumber(1);
			issueSub2.setIttl_unitName(stkIssue2Form.getUnitName1());
			issueSub2.setIttl_division(stkIssue2Form.getDivision1());			
			
			//issueSub2.setShelfCode( request.getParameter("shelfCode1") );
//			BCShelfBean shelf = new BCShelfBean();
////			shelf.setCode(request.getParameter("shelfCode1"));
//			shelf.setCode("10");
//			issueSub2.setBcShelf(shelf);
			issueSub2.setShelfCode("10");
			issueSub2.setIttl_status("0");
			issueSub2.setBcStkIssue2(issue2);

			issueSub2.setPersonCode(stkIssue2Form.getPersonCode());
			issueSub2.setProjectCode(stkIssue2Form.getProjectCode());
			
			s.add(issueSub2);
		}
		
		if(stkIssue2Form.getItemCode2() != null) {
			BCStkIssueSub2 issueSub2 = new BCStkIssueSub2();
			
			issueSub2.setDepartCode(stkIssue2Form.getDepartCode());
			issueSub2.setDocDate(new Date());
			issueSub2.setIssueType(stkIssue2Form.getIssueType());
			
			issueSub2.setItemCode(stkIssue2Form.getItemCode2());
			issueSub2.setItemName(stkIssue2Form.getItemName2());
			issueSub2.setIttl_itemCode_ttl2(stkIssue2Form.getShortName2());
			issueSub2.setQty(Float.valueOf(stkIssue2Form.getQty2()));
			issueSub2.setRemainQty(Float.valueOf(stkIssue2Form.getQty2()));
			issueSub2.setPrice(Double.valueOf(stkIssue2Form.getPrice2()));
			issueSub2.setAmount(Double.valueOf(stkIssue2Form.getAmount2()));			
			issueSub2.setUnitCode(stkIssue2Form.getUnitCode2());
			
//			BCItemUnitBean itemU = new BCItemUnitBean();
//			itemU.setCode(stkIssue2Form.getUnitCode2());
//			issueSub2.setBcitemUnit(itemU);
			
//			issueSub2.setWhCode(stkIssue2Form.getWhCode2());
			issueSub2.setWhCode("10");
			issueSub2.setIttl_status("0");
			issueSub2.setLineNumber(2);
			issueSub2.setIttl_unitName(stkIssue2Form.getUnitName2());
			issueSub2.setIttl_division(stkIssue2Form.getDivision2());			
			//issueSub2.setShelfCode(stkIssue2Form.getShelfCode2());				
			//issueSub2.setShelfCode( request.getParameter("shelfCode2") );
//			BCShelfBean shelf = new BCShelfBean();
////			shelf.setCode(request.getParameter("shelfCode2"));
//			shelf.setCode("10");
//			issueSub2.setBcShelf(shelf);
			issueSub2.setShelfCode("10");
			issueSub2.setBcStkIssue2(issue2);

			issueSub2.setPersonCode(stkIssue2Form.getPersonCode());
			issueSub2.setProjectCode(stkIssue2Form.getProjectCode());
			
			s.add(issueSub2);
		}		
		
		if( stkIssue2Form.getItemCode3() != null) {
			BCStkIssueSub2 issueSub2 = new BCStkIssueSub2();
			
			issueSub2.setDepartCode(stkIssue2Form.getDepartCode());
			issueSub2.setDocDate(new Date());
			issueSub2.setIssueType(stkIssue2Form.getIssueType());
			
			issueSub2.setItemCode(stkIssue2Form.getItemCode3());
			issueSub2.setItemName(stkIssue2Form.getItemName3());
			issueSub2.setIttl_itemCode_ttl2(stkIssue2Form.getShortName3());
			issueSub2.setQty(Float.valueOf(stkIssue2Form.getQty3()));
			issueSub2.setRemainQty(Float.valueOf(stkIssue2Form.getQty3()));
			issueSub2.setPrice(Double.valueOf(stkIssue2Form.getPrice3()));
			issueSub2.setAmount(Double.valueOf(stkIssue2Form.getAmount3()));			
			issueSub2.setUnitCode(stkIssue2Form.getUnitCode3());
//			BCItemUnitBean itemU = new BCItemUnitBean();
//			itemU.setCode(stkIssue2Form.getUnitCode3());
//			issueSub2.setBcitemUnit(itemU);

			
//			issueSub2.setWhCode(stkIssue2Form.getWhCode3());
			issueSub2.setWhCode("10");
			issueSub2.setIttl_status("0");
			issueSub2.setLineNumber(3);
			issueSub2.setIttl_unitName(stkIssue2Form.getUnitName3());
			issueSub2.setIttl_division(stkIssue2Form.getDivision3());			
			//issueSub2.setShelfCode(stkIssue2Form.getShelfCode3());				
			//issueSub2.setShelfCode( request.getParameter("shelfCode3") );
//			BCShelfBean shelf = new BCShelfBean();
////			shelf.setCode(request.getParameter("shelfCode3"));
//			shelf.setCode("10");
//			issueSub2.setBcShelf(shelf);
			issueSub2.setShelfCode("10");
			
			issueSub2.setBcStkIssue2(issue2);
			issueSub2.setPersonCode(stkIssue2Form.getPersonCode());
			issueSub2.setProjectCode(stkIssue2Form.getProjectCode());
			
			s.add(issueSub2);
		}		
		
		if(stkIssue2Form.getItemCode4() != null) {
			BCStkIssueSub2 issueSub2 = new BCStkIssueSub2();
			
			issueSub2.setDepartCode(stkIssue2Form.getDepartCode());
			issueSub2.setDocDate(new Date());
			issueSub2.setIssueType(stkIssue2Form.getIssueType());
			
			issueSub2.setItemCode(stkIssue2Form.getItemCode4());
			issueSub2.setItemName(stkIssue2Form.getItemName4());
			issueSub2.setIttl_itemCode_ttl2(stkIssue2Form.getShortName4());
			issueSub2.setQty(Float.valueOf(stkIssue2Form.getQty4()));
			issueSub2.setRemainQty(Float.valueOf(stkIssue2Form.getQty4()));
			issueSub2.setPrice(Double.valueOf(stkIssue2Form.getPrice4()));
			issueSub2.setAmount(Double.valueOf(stkIssue2Form.getAmount4()));			
			issueSub2.setUnitCode(stkIssue2Form.getUnitCode4());
//			BCItemUnitBean itemU = new BCItemUnitBean();
//			itemU.setCode(stkIssue2Form.getUnitCode4());
//			issueSub2.setBcitemUnit(itemU);
			
//			issueSub2.setWhCode(stkIssue2Form.getWhCode4());
			issueSub2.setWhCode("10");
			issueSub2.setIttl_status("0");
			issueSub2.setLineNumber(4);
			issueSub2.setIttl_unitName(stkIssue2Form.getUnitName4());
			issueSub2.setIttl_division(stkIssue2Form.getDivision4());			
			//issueSub2.setShelfCode(stkIssue2Form.getShelfCode4());				
			//issueSub2.setShelfCode( request.getParameter("shelfCode4") );
//			BCShelfBean shelf = new BCShelfBean();
////			shelf.setCode(request.getParameter("shelfCode4"));
//			shelf.setCode("10");
//			issueSub2.setBcShelf(shelf);
			issueSub2.setShelfCode("10");
			
			
			issueSub2.setBcStkIssue2(issue2);
			issueSub2.setPersonCode(stkIssue2Form.getPersonCode());
			issueSub2.setProjectCode(stkIssue2Form.getProjectCode());
			
			s.add(issueSub2);
		}
				
		issue2.setBcStkIssueSub2s(s);
							
		BCStkIssue2DAO dao = new BCStkIssue2DAO();		
		dao.update(issue2.getDocNo(),issue2);
								
		return true;

	}
	
	@SuppressWarnings("unchecked")
	public boolean update2(ActionForm form, HttpServletRequest request,
			HttpServletResponse response) {

		BCStkIssue2Form stkIssue2Form = setForm(request);//(BCStkIssue2Form)form;
		
		BCIssueTypeBean issueType = new BCIssueTypeBean();
		issueType.setCode(request.getParameter("issueType"));			
		BCProjectBean proj = new BCProjectBean();
		proj.setCode(stkIssue2Form.getProjectCode());
		
		BCStkIssue2 issue2 = new BCStkIssue2();
		issue2.setBcIssueTypeBean(issueType);
		issue2.setProjectCode(stkIssue2Form.getProjectCode());
		issue2.setiTTL_status("1");
		issue2.setBillStatus(1);
		issue2.setIsCancel(0);
		issue2.setIttl_userLevel((Integer)request.getSession().getAttribute("userLevel"));
		issue2.setDocNo(stkIssue2Form.getDocNo());
		issue2.setCreatorCode(stkIssue2Form.getPersonCode());
		issue2.setDepartCode(stkIssue2Form.getDepartCode());					        	       
	    issue2.setDocDate(CommonUtils.convertStringToDate(stkIssue2Form.getDocDate()));
	       	    	  								
		issue2.setIsCompleteSave(1);
		issue2.setIssueType(stkIssue2Form.getIssueType());
		issue2.setiTTL_orderNo(stkIssue2Form.getOrderNo());
		issue2.setiTTL_deptPay(stkIssue2Form.getiTTL_deptPay());
		issue2.setPersonCode(stkIssue2Form.getPersonCode());
		issue2.setMyDescription(stkIssue2Form.getMyDescription());
		
		HashSet s = new HashSet();			
		
		if( stkIssue2Form.getItemCode1() != null) {
			BCStkIssueSub2 issueSub2 = new BCStkIssueSub2();
			
			issueSub2.setDepartCode(stkIssue2Form.getDepartCode());
			issueSub2.setDocDate(new Date());
			issueSub2.setIssueType(stkIssue2Form.getIssueType());
			
			issueSub2.setItemCode(stkIssue2Form.getItemCode1());
			issueSub2.setItemName(stkIssue2Form.getItemName1());
			issueSub2.setQty(Float.valueOf(stkIssue2Form.getQty1()));
			issueSub2.setRemainQty(Float.valueOf(stkIssue2Form.getQty1()));
										
			issueSub2.setPrice(Double.valueOf(stkIssue2Form.getPrice1()));
			issueSub2.setAmount(Double.valueOf(stkIssue2Form.getAmount1()));
			
//			BCItemUnitBean itemU = new BCItemUnitBean();
//			itemU.setCode(stkIssue2Form.getUnitCode1());
//			issueSub2.setBcitemUnit(itemU);
			issueSub2.setUnitCode(stkIssue2Form.getUnitCode1());
			
//			issueSub2.setWhCode(stkIssue2Form.getWhCode1());
			issueSub2.setWhCode("10");
			
			issueSub2.setLineNumber(1);
			issueSub2.setIttl_unitName(stkIssue2Form.getUnitName1());
			issueSub2.setIttl_division(stkIssue2Form.getDivision1());			
			
			//issueSub2.setShelfCode( request.getParameter("shelfCode1") );
//			BCShelfBean shelf = new BCShelfBean();
////			shelf.setCode(request.getParameter("shelfCode1"));
//			shelf.setCode("10");
//			
//			issueSub2.setBcShelf(shelf);
			issueSub2.setShelfCode("10");
			
			issueSub2.setBcStkIssue2(issue2);

			issueSub2.setPersonCode(stkIssue2Form.getPersonCode());
			issueSub2.setProjectCode(stkIssue2Form.getProjectCode());
			
			s.add(issueSub2);
		}
		
		if(stkIssue2Form.getItemCode2() != null) {
			BCStkIssueSub2 issueSub2 = new BCStkIssueSub2();
			
			issueSub2.setDepartCode(stkIssue2Form.getDepartCode());
			issueSub2.setDocDate(new Date());
			issueSub2.setIssueType(stkIssue2Form.getIssueType());
			
			issueSub2.setItemCode(stkIssue2Form.getItemCode2());
			issueSub2.setItemName(stkIssue2Form.getItemName2());
			issueSub2.setQty(Float.valueOf(stkIssue2Form.getQty2()));
			issueSub2.setRemainQty(Float.valueOf(stkIssue2Form.getQty2()));
			issueSub2.setPrice(Double.valueOf(stkIssue2Form.getPrice2()));
			issueSub2.setAmount(Double.valueOf(stkIssue2Form.getAmount2()));			
			issueSub2.setUnitCode(stkIssue2Form.getUnitCode2());
			
//			BCItemUnitBean itemU = new BCItemUnitBean();
//			itemU.setCode(stkIssue2Form.getUnitCode2());
//			issueSub2.setBcitemUnit(itemU);
			
//			issueSub2.setWhCode(stkIssue2Form.getWhCode2());
			issueSub2.setWhCode("10");
			
			issueSub2.setLineNumber(2);
			issueSub2.setIttl_unitName(stkIssue2Form.getUnitName2());
			issueSub2.setIttl_division(stkIssue2Form.getDivision2());			
			//issueSub2.setShelfCode(stkIssue2Form.getShelfCode2());				
			//issueSub2.setShelfCode( request.getParameter("shelfCode2") );
//			BCShelfBean shelf = new BCShelfBean();
////			shelf.setCode(request.getParameter("shelfCode2"));
//			shelf.setCode("10");
//			issueSub2.setBcShelf(shelf);
			issueSub2.setShelfCode("10");
			
			issueSub2.setBcStkIssue2(issue2);

			issueSub2.setPersonCode(stkIssue2Form.getPersonCode());
			issueSub2.setProjectCode(stkIssue2Form.getProjectCode());
			
			s.add(issueSub2);
		}		
		
		if( stkIssue2Form.getItemCode3() != null) {
			BCStkIssueSub2 issueSub2 = new BCStkIssueSub2();
			
			issueSub2.setDepartCode(stkIssue2Form.getDepartCode());
			issueSub2.setDocDate(new Date());
			issueSub2.setIssueType(stkIssue2Form.getIssueType());
			
			issueSub2.setItemCode(stkIssue2Form.getItemCode3());
			issueSub2.setItemName(stkIssue2Form.getItemName3());
			issueSub2.setQty(Float.valueOf(stkIssue2Form.getQty3()));
			issueSub2.setRemainQty(Float.valueOf(stkIssue2Form.getQty3()));
			issueSub2.setPrice(Double.valueOf(stkIssue2Form.getPrice3()));
			issueSub2.setAmount(Double.valueOf(stkIssue2Form.getAmount3()));			
			issueSub2.setUnitCode(stkIssue2Form.getUnitCode3());
//			BCItemUnitBean itemU = new BCItemUnitBean();
//			itemU.setCode(stkIssue2Form.getUnitCode3());
//			issueSub2.setBcitemUnit(itemU);
			
//			issueSub2.setWhCode(stkIssue2Form.getWhCode3());
			issueSub2.setWhCode("10");
			
			issueSub2.setLineNumber(3);
			issueSub2.setIttl_unitName(stkIssue2Form.getUnitName3());
			issueSub2.setIttl_division(stkIssue2Form.getDivision3());			
			//issueSub2.setShelfCode(stkIssue2Form.getShelfCode3());				
			//issueSub2.setShelfCode( request.getParameter("shelfCode3") );
//			BCShelfBean shelf = new BCShelfBean();
////			shelf.setCode(request.getParameter("shelfCode3"));
//			shelf.setCode("10");
//			issueSub2.setBcShelf(shelf);
			issueSub2.setShelfCode("10");
			
			issueSub2.setBcStkIssue2(issue2);
			issueSub2.setPersonCode(stkIssue2Form.getPersonCode());
			issueSub2.setProjectCode(stkIssue2Form.getProjectCode());
			
			s.add(issueSub2);
		}		
		
		if(stkIssue2Form.getItemCode4() != null) {
			BCStkIssueSub2 issueSub2 = new BCStkIssueSub2();
			
			issueSub2.setDepartCode(stkIssue2Form.getDepartCode());
			issueSub2.setDocDate(new Date());
			issueSub2.setIssueType(stkIssue2Form.getIssueType());
			
			issueSub2.setItemCode(stkIssue2Form.getItemCode4());
			issueSub2.setItemName(stkIssue2Form.getItemName4());
			issueSub2.setQty(Float.valueOf(stkIssue2Form.getQty4()));
			issueSub2.setRemainQty(Float.valueOf(stkIssue2Form.getQty4()));
			issueSub2.setPrice(Double.valueOf(stkIssue2Form.getPrice4()));
			issueSub2.setAmount(Double.valueOf(stkIssue2Form.getAmount4()));			
			issueSub2.setUnitCode(stkIssue2Form.getUnitCode4());
//			BCItemUnitBean itemU = new BCItemUnitBean();
//			itemU.setCode(stkIssue2Form.getUnitCode4());
//			issueSub2.setBcitemUnit(itemU);
			
//			issueSub2.setWhCode(stkIssue2Form.getWhCode4());
			issueSub2.setWhCode("10");
			
			issueSub2.setLineNumber(4);
			issueSub2.setIttl_unitName(stkIssue2Form.getUnitName4());
			issueSub2.setIttl_division(stkIssue2Form.getDivision4());			
			//issueSub2.setShelfCode(stkIssue2Form.getShelfCode4());				
			//issueSub2.setShelfCode( request.getParameter("shelfCode4") );
//			BCShelfBean shelf = new BCShelfBean();
////			shelf.setCode(request.getParameter("shelfCode4"));
//			shelf.setCode("10");
//			issueSub2.setBcShelf(shelf);
			issueSub2.setShelfCode("10");
			
			issueSub2.setBcStkIssue2(issue2);
			issueSub2.setPersonCode(stkIssue2Form.getPersonCode());
			issueSub2.setProjectCode(stkIssue2Form.getProjectCode());
			
			s.add(issueSub2);
		}
				
		issue2.setBcStkIssueSub2s(s);
							
		BCStkIssue2DAO dao = new BCStkIssue2DAO();		
		dao.update(issue2.getDocNo(),issue2);
								
		return true;

	}	

	@SuppressWarnings("unchecked")
	public boolean updatePrice(ActionForm form, HttpServletRequest request,
			HttpServletResponse response) {
		update2(form, request, response);
		
		ArrayList al = getlineItemList(request);
		
		BCStkIssueDAO dao = new BCStkIssueDAO();						 
								
		return dao.updatePrice(al);
	}

	@SuppressWarnings("unchecked")
	private ArrayList getlineItemList(HttpServletRequest request) {

		ArrayList al = new ArrayList();
				
		for(int i=1; i<=4; i++) {
			if(request.getParameter("itemCode"+i)!= null ) {				
				BCStkIssueSubBean sub = new BCStkIssueSubBean();
				sub.setRefNo(request.getParameter("docNo"));
				sub.setItemCode(request.getParameter("itemCode"+i));
				sub.setPrice(Float.parseFloat(request.getParameter("price"+i)));
				sub.setAmount(Float.parseFloat(request.getParameter("amount"+i)));
				al.add(sub);
			}
		}
				
		return al;
	}

	public boolean delete(ActionForm form, HttpServletRequest request,
			HttpServletResponse response) {
		
		String docNo = (String)request.getParameter("docNo");
		String hql = "from BCStkIssue2 where docNo = '"+docNo+"'";
		
		System.out.println("#docNo :"+docNo);
		
		BCStkIssue2DAO dao = new BCStkIssue2DAO();
		dao.delete(hql);		
		
		request.setAttribute("docNoFind", docNo.substring(6, docNo.length()));
		
		return true;
	}

	public boolean restore(ActionForm form, HttpServletRequest request,
			HttpServletResponse response) {
		
		String docNo = (String)request.getParameter("docNo");
		String hql = "from BCStkIssue2 where docNo = '"+docNo+"'";
		
		System.out.println("#docNo :"+docNo);
		
		BCStkIssue2DAO dao = new BCStkIssue2DAO();
		dao.restore(hql);		
		
		request.setAttribute("docNoFind", docNo.substring(9, docNo.length()));
		
		return true;
	}

	@SuppressWarnings("unchecked")
	public static BCStkIssue2 setRequestObject(BCStkIssue2Form stkIssue2Form, HttpServletRequest request) {

		BCIssueTypeBean issueType = new BCIssueTypeBean();
		issueType.setCode(request.getParameter("issueType"));			
		
		BCProjectBean proj = new BCProjectBean();
		proj.setCode(stkIssue2Form.getProjectCode());
		
		BCStkIssue2 issue2 = new BCStkIssue2();
		issue2.setBcIssueTypeBean(issueType);
		//issue2.setBcProjectBean(proj);
		issue2.setProjectCode(stkIssue2Form.getProjectCode());
		issue2.setiTTL_status("0");
		issue2.setBillStatus(0);
		issue2.setIsCancel(0);
		issue2.setIttl_userLevel((Integer)request.getSession().getAttribute("userLevel"));			
		issue2.setDocNo(stkIssue2Form.getDocNo());
		issue2.setCreatorCode(stkIssue2Form.getPersonCode());
		issue2.setDepartCode(stkIssue2Form.getDepartCode());
					
//		try {    							    
//			String str_date = stkIssue2Form.getDocDate();
//		
//        	DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); 
//        	Date date = (Date)formatter.parse(str_date);    		        		        		        
//	        issue2.setDocDate(date);
//	        issue2.setCreateDateTime(new Date());		        
//	   } catch (ParseException e) {
//		   System.out.println("Exception :"+e);    
//	   }
        issue2.setDocDate(CommonUtils.convertStringToDate(stkIssue2Form.getDocDate()));
        issue2.setCreateDateTime(new Date());
	   
		
		issue2.setIsCompleteSave(1);
		issue2.setIssueType(stkIssue2Form.getIssueType());
		issue2.setiTTL_orderNo(stkIssue2Form.getOrderNo());
		issue2.setiTTL_deptPay(stkIssue2Form.getiTTL_deptPay());
		issue2.setPersonCode(stkIssue2Form.getPersonCode());
		//issue2.setProjectCode(stkIssue2Form.getProjectCode());
		issue2.setMyDescription(stkIssue2Form.getMyDescription());
//		issue2.setMyDescription(new String(stkIssue2Form.getMyDescription().getBytes("ISO8859_1"),"utf-8"));
		
		HashSet s = new HashSet();			
		
//		issueSub2.setBcStkIssue2(issue2);
		
		if( stkIssue2Form.getItemCode1() != null) {
			BCStkIssueSub2 issueSub2 = new BCStkIssueSub2();
			
			issueSub2.setDepartCode(stkIssue2Form.getDepartCode());
			issueSub2.setDocDate(new Date());
			issueSub2.setIssueType(stkIssue2Form.getIssueType());				
			issueSub2.setItemCode(stkIssue2Form.getItemCode1());
			issueSub2.setItemName(stkIssue2Form.getItemName1());
			issueSub2.setIttl_itemCode_ttl2(stkIssue2Form.getShortName1());
			issueSub2.setQty(Float.valueOf(stkIssue2Form.getQty1()));
			issueSub2.setRemainQty(Float.valueOf(stkIssue2Form.getQty1()));
			
			issueSub2.setPrice(Double.valueOf(stkIssue2Form.getPrice1()));
			issueSub2.setAmount(issueSub2.getQty()*issueSub2.getPrice());
			
			issueSub2.setUnitCode(stkIssue2Form.getUnitCode1());
//			BCItemUnitBean itemU = new BCItemUnitBean();
//			itemU.setCode(stkIssue2Form.getUnitCode1());
//			issueSub2.setBcitemUnit(itemU);				
//			issueSub2.setWhCode(stkIssue2Form.getWhCode1());
			issueSub2.setWhCode("10");
			
			issueSub2.setLineNumber(1);
			issueSub2.setIttl_unitName(stkIssue2Form.getUnitName1());
			issueSub2.setIttl_division(stkIssue2Form.getDivision1());								
			
			//issueSub2.setShelfCode( request.getParameter("shelfCode1") );
//			BCShelfBean shelf = new BCShelfBean();
////			shelf.setCode(request.getParameter("shelfCode1"));
//			shelf.setCode("10");
//			issueSub2.setBcShelf(shelf);
			issueSub2.setShelfCode("10");
			issueSub2.setBcStkIssue2(issue2);
			
			issueSub2.setPersonCode(stkIssue2Form.getPersonCode());
			issueSub2.setProjectCode(stkIssue2Form.getProjectCode());
			issueSub2.setCreatorCode(stkIssue2Form.getPersonCode());
			issueSub2.setCreateDateTime(issue2.getCreateDateTime());
			
			s.add(issueSub2);
		}
		
		if(stkIssue2Form.getItemCode2() != null) {
			BCStkIssueSub2 issueSub2 = new BCStkIssueSub2();
			
			issueSub2.setDepartCode(stkIssue2Form.getDepartCode());
			issueSub2.setDocDate(new Date());
			issueSub2.setIssueType(stkIssue2Form.getIssueType());				
			issueSub2.setItemCode(stkIssue2Form.getItemCode2());
			issueSub2.setItemName(stkIssue2Form.getItemName2());
			issueSub2.setIttl_itemCode_ttl2(stkIssue2Form.getShortName2());
			issueSub2.setQty(Float.valueOf(stkIssue2Form.getQty2()));
			issueSub2.setRemainQty(Float.valueOf(stkIssue2Form.getQty2()));

			issueSub2.setPrice(Double.valueOf(stkIssue2Form.getPrice2()));
			issueSub2.setAmount(issueSub2.getQty()*issueSub2.getPrice());
			
			issueSub2.setUnitCode(stkIssue2Form.getUnitCode2());
//			BCItemUnitBean itemU = new BCItemUnitBean();
//			itemU.setCode(stkIssue2Form.getUnitCode2());
//			issueSub2.setBcitemUnit(itemU);
			
//			issueSub2.setWhCode(stkIssue2Form.getWhCode2());
			issueSub2.setWhCode("10");
			
			issueSub2.setLineNumber(2);
			issueSub2.setIttl_unitName(stkIssue2Form.getUnitName2());
			issueSub2.setIttl_division(stkIssue2Form.getDivision2());
			
			//issueSub2.setShelfCode(stkIssue2Form.getShelfCode2());				
			//issueSub2.setShelfCode( request.getParameter("shelfCode2") );
//			BCShelfBean shelf = new BCShelfBean();
////			shelf.setCode(request.getParameter("shelfCode2"));
//			shelf.setCode("10");
//			
//			issueSub2.setBcShelf(shelf);
			issueSub2.setShelfCode("10");
			issueSub2.setBcStkIssue2(issue2);

			issueSub2.setPersonCode(stkIssue2Form.getPersonCode());
			issueSub2.setProjectCode(stkIssue2Form.getProjectCode());
			issueSub2.setCreatorCode(stkIssue2Form.getPersonCode());
			issueSub2.setCreateDateTime(issue2.getCreateDateTime());
			
			s.add(issueSub2);
		}		
		
		if( stkIssue2Form.getItemCode3() != null) {
			BCStkIssueSub2 issueSub2 = new BCStkIssueSub2();				
			issueSub2.setDepartCode(stkIssue2Form.getDepartCode());
			issueSub2.setDocDate(new Date());
			issueSub2.setIssueType(stkIssue2Form.getIssueType());
			
			issueSub2.setItemCode(stkIssue2Form.getItemCode3());
			issueSub2.setItemName(stkIssue2Form.getItemName3());
			issueSub2.setIttl_itemCode_ttl2(stkIssue2Form.getShortName3());
			issueSub2.setQty(Float.valueOf(stkIssue2Form.getQty3()));
			issueSub2.setRemainQty(Float.valueOf(stkIssue2Form.getQty3()));
			
			issueSub2.setPrice(Double.valueOf(stkIssue2Form.getPrice3()));
			issueSub2.setAmount(issueSub2.getQty()*issueSub2.getPrice());
			
			issueSub2.setUnitCode(stkIssue2Form.getUnitCode3());
//			BCItemUnitBean itemU = new BCItemUnitBean();
//			itemU.setCode(stkIssue2Form.getUnitCode3());
//			issueSub2.setBcitemUnit(itemU);
			
//			issueSub2.setWhCode(stkIssue2Form.getWhCode3());
			issueSub2.setWhCode("10");				
			issueSub2.setLineNumber(3);
			issueSub2.setIttl_unitName(stkIssue2Form.getUnitName3());
			issueSub2.setIttl_division(stkIssue2Form.getDivision3());
			
			//issueSub2.setShelfCode(stkIssue2Form.getShelfCode3());				
			//issueSub2.setShelfCode( request.getParameter("shelfCode3") );
//			BCShelfBean shelf = new BCShelfBean();
////			shelf.setCode(request.getParameter("shelfCode3"));
//			shelf.setCode("10");
//			
//			issueSub2.setBcShelf(shelf);
			issueSub2.setShelfCode("10");
			issueSub2.setBcStkIssue2(issue2);
			
			issueSub2.setPersonCode(stkIssue2Form.getPersonCode());
			issueSub2.setProjectCode(stkIssue2Form.getProjectCode());
			issueSub2.setCreatorCode(stkIssue2Form.getPersonCode());
			issueSub2.setCreateDateTime(issue2.getCreateDateTime());
			
			s.add(issueSub2);
		}		
		
		if(stkIssue2Form.getItemCode4() != null) {
			BCStkIssueSub2 issueSub2 = new BCStkIssueSub2();				
			issueSub2.setDepartCode(stkIssue2Form.getDepartCode());
			issueSub2.setDocDate(new Date());
			issueSub2.setIssueType(stkIssue2Form.getIssueType());				
			issueSub2.setItemCode(stkIssue2Form.getItemCode4());
			issueSub2.setItemName(stkIssue2Form.getItemName4());
			issueSub2.setIttl_itemCode_ttl2(stkIssue2Form.getShortName4());
			issueSub2.setQty(Float.valueOf(stkIssue2Form.getQty4()));
			issueSub2.setRemainQty(Float.valueOf(stkIssue2Form.getQty4()));
			
			issueSub2.setPrice(Double.valueOf(stkIssue2Form.getPrice4()));
			issueSub2.setAmount(issueSub2.getQty()*issueSub2.getPrice());
			
			issueSub2.setUnitCode(stkIssue2Form.getUnitCode4());
//			BCItemUnitBean itemU = new BCItemUnitBean();
//			itemU.setCode(stkIssue2Form.getUnitCode4());
//			issueSub2.setBcitemUnit(itemU);
			
//			issueSub2.setWhCode(stkIssue2Form.getWhCode4());
			issueSub2.setWhCode("10");				
			issueSub2.setLineNumber(4);
			issueSub2.setIttl_unitName(stkIssue2Form.getUnitName4());
			issueSub2.setIttl_division(stkIssue2Form.getDivision4());
			
			//issueSub2.setShelfCode(stkIssue2Form.getShelfCode4());				
			//issueSub2.setShelfCode( request.getParameter("shelfCode4") );
//			BCShelfBean shelf = new BCShelfBean();
////			shelf.setCode(request.getParameter("shelfCode4"));
//			shelf.setCode("10");
//			issueSub2.setBcShelf(shelf);
			issueSub2.setShelfCode("10");
			issueSub2.setBcStkIssue2(issue2);
			
			issueSub2.setPersonCode(stkIssue2Form.getPersonCode());
			issueSub2.setProjectCode(stkIssue2Form.getProjectCode());
			issueSub2.setCreatorCode(stkIssue2Form.getPersonCode());
			issueSub2.setCreateDateTime(issue2.getCreateDateTime());
			
			s.add(issueSub2);
		}
					
		issue2.setBcStkIssueSub2s(s);
		
		return issue2;

	}

	public void showFind(HttpServletRequest request) throws UnsupportedEncodingException {
		
		String userName = (String)request.getSession().getAttribute("userName");			
		String monthFind = (String)request.getParameter("monthFind");
		String yearFind = (String)request.getParameter("yearFind");

		@SuppressWarnings("unused")
		String preDocNo  = (String)request.getSession().getAttribute("preDocNo")+"";
		@SuppressWarnings("unused")
		int userLevel =  (Integer)request.getSession().getAttribute("userLevel");		

		String	itemFind = "";
		if(request.getParameter("itemFind")!=null) {
			itemFind = ((String)request.getParameter("itemFind"));
			itemFind = new String(itemFind.getBytes("ISO8859_1"),"UTF-8");
			request.setAttribute("itemFind", itemFind.trim());
		}		
//-------------------		
		 
		 
		 preDocNo  = (String)request.getParameter("deptFind");
		request.setAttribute("deptFind", preDocNo);
		
		String dateFind = "";
		if(request.getParameter("dateFind")!=null) {
			dateFind = ((String)request.getParameter("dateFind"));
			dateFind = new String(dateFind.getBytes("ISO8859_1"),"UTF-8");
			request.setAttribute("dateFind", dateFind.trim());
		}		
		String ittl_status = (String)request.getParameter("ittl_status2");
		request.setAttribute("ittl_status2", ittl_status);
		System.out.println("ittl_status="+ittl_status);		
		
//----------------------		
		if(monthFind==null) {			
			monthFind = CommonUtils.getCurrentDateFormat("MM");										
		}
		
		if(yearFind==null) {
			yearFind = CommonUtils.getCurrentDateFormat("yyyyy");
			
			if (Integer.parseInt(yearFind)<2500) {								
				yearFind = (""+(Integer.parseInt(yearFind)+543)).substring(2);			
			}else {
				yearFind = yearFind.substring(2);
			}			
		}
				
		request.getSession().setAttribute("monthFind", monthFind);
		request.getSession().setAttribute("yearFind", yearFind);
		
		List<ITTL_UserDepartment> userInDepartmentList =  (List<ITTL_UserDepartment>)request.getSession().getAttribute("userInDepartmentList");
		String createorCode = "";
		if(userInDepartmentList!=null && userInDepartmentList.size()>0) {
			for (ITTL_UserDepartment userInDept : userInDepartmentList) {
				createorCode = createorCode+"'"+userInDept.getUserInDepartment()+"',";
			}
			createorCode = createorCode + "'"+userName+"'";
		}
		
		String hql = "";
		if(itemFind==null||itemFind.trim().equals("")) {
//			hql = "FROM BCStkIssue2 s  " +
//					 "WHERE upper(s.creatorCode)='"+userName.toUpperCase()+"' " +
////					 "and s.docNo like '"+preDocNo+"-"+yearFind+monthFind+"%' "+
////					 "and s.isCancel =0 "+
//					 "ORDER BY s.docNo desc";	
			hql = "FROM BCStkIssue2 s WHERE s.creatorCode in ("+createorCode+") ";
		}else {
//			hql = "FROM BCStkIssue2 s  " +
//					 "WHERE upper(s.creatorCode)='"+userName.toUpperCase()+"' " +
//					 "and s.docNo like '%"+itemFind.trim()+"%' "+					 
////					 "and s.docNo like '"+preDocNo+"-%"+docNoFind.trim()+"%' "+
////					 "and s.isCancel =0 "+
//					 "ORDER BY s.docNo desc";
			
			hql = "FROM BCStkIssue2 s WHERE s.creatorCode in ("+createorCode+") " +
					" and s.docNo like '%"+itemFind.trim()+"%' " ;
		}		
		
		//--------------------start
//		if(itemFind!=null && !itemFind.trim().equals("")) {
//			hql += " and docNo like '%"+itemFind.trim()+"%' ";
//		}
		if(preDocNo!=null && !preDocNo.equals("")) {
			hql += " and docNo like '"+preDocNo+"%' ";
		}		
		if(dateFind!=null && !dateFind.trim().equals("")) {
			hql += " and docNo like '%"+dateFind+"%' ";
		}
		if(ittl_status!=null && !ittl_status.equals("all") && !ittl_status.equals("")) {
			hql += " and ittl_status = '"+ittl_status+"' ";
		}
		//------------------end
		
		System.out.println(hql);
		Page.setPage(request, hql);
	}
}
